const db = require("../config/config");
module.exports = {
  //根据用户id，，获取该用户购物车信息
  updateMemberInfo(req, res) {
    console.log(req.body,'req');
    let user_name=req.body.user_name
    let user_enable=req.body.user_enable
    let user_id=req.body.user_id
    let user_email=req.body.user_email
    let user_type=req.body.user_type
    let user_pwd=req.body.user_newPwd
    let user_phone=req.body.user_phone
    if(user_type=='administrator'){
        user_type=1
      }
      else if(user_type=='member'){
       user_type=2
      }
      else if(user_type=='user'){
       user_type=3
      }
    console.log(user_id,user_email,user_name,user_phone,user_type,user_pwd,user_enable);
    db.dbMysql(`UPDATE user SET user_email =? ,user_name =?,user_phone =?,user_type =?,user_pwd=?,user_enable=?  WHERE user_id = ?`, [user_email,user_name,user_phone,user_type,user_pwd,user_enable,user_id], function (err, data) {
        console.log(data,'data');
        // console.log(err,'err');
     for(let i=0;i<data.length;i++){
      if(data[i].user_type==0){
           data[i].user_type=true
      }
      else{
        data[i].user_type=false
      }
     }

      if (data) {
        res.send({
          code: 200,
          data: data,
          msg: "角色管理查询成功",
        });
      } else {
        res.send({
          code: 500,
          msg: "服务器错误",
        });
      }
    });
  },
};
